﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SimpleMvvmToolkit;

namespace GUIEXAM13
{
    public class Clothing: ModelBase<Clothing>
    {
        private ClothingDataAccess _clothingDataAccess;

        public Clothing()
        {
            _clothingDataAccess = new ClothingDataAccess();
            LoadAllClothing();
        }

        private ObservableCollection<ClothingDomain> _allClothing;
        public ObservableCollection<ClothingDomain> AllClothing
        {
            get { return _allClothing = _allClothing ?? new ObservableCollection<ClothingDomain>(); }
            set
            {
                _allClothing = value;
                NotifyPropertyChanged(m => m.AllClothing);
            }
        }

        public void LoadAllClothing()
        {
            var bgWorker = new BackgroundWorker();
            bgWorker.DoWork += (sender, args) => AllClothing = _clothingDataAccess.GetAllClothing();
            bgWorker.RunWorkerAsync();
        }

        public void SaveAllClothing()
        {
            var bgWorker = new BackgroundWorker();
            bgWorker.DoWork += (sender, args) => _clothingDataAccess.SaveAllClothing(AllClothing);
            bgWorker.RunWorkerAsync();
        }
    }
}
